package database;

public class dbCharacterImpl implements database.ints.dbCharacter {

    dbMain dbM=new dbMain();
    private String charID = "charID";
    private String charPid = "playerID";
    private String charName = "charName";
    private String charClass = "charClass";
    private String charStr = "charStr";
    private String charAgi = "charAgi";
    private String charVit = "charVit";
    private String charIntel = "charIntel";
    private String charLvl = "charLvl";
    private String charXp = "charXP";
    private String charPremade = "charPremade";
    private String gameID = "gameID";
    private String charActive = "charActive";
    	
    // Erstellen und loeschen eines Charakters
    @Override
	public void createCharacter(String userID, String name, String charClass, String str,
			String agi, String vit, String intel, String lvl, String xp,
			String premade) {
    	dbM.addCharacter(userID, name, charClass, str, agi, vit, intel, lvl, xp, premade);
	}

	@Override
	public void deleteCharacter(String name) {
		dbM.deleteRow(dbM.URL_CHAR, charName, name);
	}
    
    // Getters
	@Override
	public String getCharID(String cname) {
		return dbM.getValue(dbM.URL_CHAR, charName, cname, charID);
	}
	
	@Override
	public String getUserID(String cname) {
		return dbM.getValue(dbM.URL_CHAR, charName, cname, charPid);
	}
	
	@Override
	public String getCharName(int cid) {
		return dbM.getValue(dbM.URL_CHAR, charID, Integer.toString(cid), charName);
	}

	@Override
	public String getCharClass(int cid) {
		return dbM.getValue(dbM.URL_CHAR, charID, Integer.toString(cid), charClass);
	}

	@Override
	public int getCharStr(int cid) {
		String ret = dbM.getValue(dbM.URL_CHAR, charID, Integer.toString(cid), charStr);
		return Integer.parseInt(ret);
	}

	@Override
	public int getCharAgi(int cid) {
		String ret = dbM.getValue(dbM.URL_CHAR, charID, Integer.toString(cid), charAgi);
		return Integer.parseInt(ret);
	}

	@Override
	public int getCharVit(int cid) {
		String ret = dbM.getValue(dbM.URL_CHAR, charID, Integer.toString(cid), charVit);
		return Integer.parseInt(ret);
	}

	@Override
	public int getCharIntel(int cid) {
		String ret = dbM.getValue(dbM.URL_CHAR, charID, Integer.toString(cid), charIntel);
		return Integer.parseInt(ret);
	}

	@Override
	public int getCharLvl(int cid) {
		String ret = dbM.getValue(dbM.URL_CHAR, charID, Integer.toString(cid), charLvl);
		return Integer.parseInt(ret);
	}

	@Override
	public int getCharXp(int cid) {
		String ret = dbM.getValue(dbM.URL_CHAR, charID, Integer.toString(cid), charXp);
		return Integer.parseInt(ret);
	}

	@Override
	public boolean getCharPremade(int cid) {
		String ret = dbM.getValue(dbM.URL_CHAR, charID, Integer.toString(cid), charPremade);
		if (ret.equals("true")) {
			return true;
		} else {
			return false;
		}
	}
	
	@Override
	public int getGameID(int cid,int playerID) {
		String ret = dbM.getDoubleValue(dbM.URL_CHAR, charID, Integer.toString(cid), charPid, Integer.toString(playerID), gameID);
		return Integer.parseInt(ret);
	}
	
	public void setGameID(int AnimalID,int playerID, int gameIDset) {
		dbM.updateDoubleValue(dbM.URL_CHAR, charPid, Integer.toString(playerID), charID, Integer.toString(AnimalID), gameID, Integer.toString(gameIDset));
	}
	
	public void setCharActive(int AnimalID,int playerID, int active) {
		dbM.updateDoubleValue(dbM.URL_CHAR, charPid, Integer.toString(playerID), charID, Integer.toString(AnimalID), charActive, Integer.toString(active));
	}
	
	// Setters
	@Override
	public void setCharID(int oldcid, int newcid) {
		dbM.updateValue(dbM.URL_CHAR, charID, Integer.toString(oldcid), charID, Integer.toString(newcid));
	}
	
	@Override
	public void setUserID(int olduid, int newuid) {
		dbM.updateValue(dbM.URL_CHAR, charPid, Integer.toString(olduid), charPid, Integer.toString(newuid));
	}
	
	@Override
	public void setCharName(int cid, String newCharName) {
		dbM.updateValue(dbM.URL_CHAR, charID, Integer.toString(cid), charName, newCharName);
	}

	@Override
	public void setCharClass(int cid, String newCharClass) {
		dbM.updateValue(dbM.URL_CHAR, charID, Integer.toString(cid), charClass, newCharClass);
	}

	@Override
	public void setCharStr(int cid, String newCharStr) {
		dbM.updateValue(dbM.URL_CHAR, charID, Integer.toString(cid), charStr, newCharStr);
	}

	@Override
	public void setCharAgi(int cid, String newCharAgi) {
		dbM.updateValue(dbM.URL_CHAR, charID, Integer.toString(cid), charAgi, newCharAgi);
	}

	@Override
	public void setCharVit(int cid, String newCharVit) {
		dbM.updateValue(dbM.URL_CHAR, charID, Integer.toString(cid), charVit, newCharVit);
	}

	@Override
	public void setCharIntel(int cid, String newCharIntel) {
		dbM.updateValue(dbM.URL_CHAR, charID, Integer.toString(cid), charIntel, newCharIntel);
	}

	@Override
	public void setCharLvl(int cid, String newCharLvl) {
		dbM.updateValue(dbM.URL_CHAR, charID, Integer.toString(cid), charLvl, newCharLvl);
	}

	@Override
	public void setCharXp(int cid, String newCharXp) {
		dbM.updateValue(dbM.URL_CHAR, charID, Integer.toString(cid), charXp, newCharXp);
	}

	@Override
	public void setCharPremade(int cid, String newCharPremade) {
		dbM.updateValue(dbM.URL_CHAR, charID, Integer.toString(cid), charPremade, newCharPremade);
	}

	@Override
	public String[] getActiveEnemies() {
		String[] enemies = dbM.getEnemies();
		return enemies;
	}
}
